﻿/*
方法：定义通用的工具栏操作方法
作者：江怀玉
日期：2012-08-28


用于列表的菜单按钮方法,表单工具栏按钮
*/
var iSunToolButton = {
    verison: "0.1",
    author: "江怀玉",
    //增新
    fnAdd: function () {
        if (typeof (fnCustomAdd) == "function") {
            fnCustomAdd();
            return;
        }
        _fnAdd();
    },
    //编辑
    fnEdit: function () {

        if (typeof (fnCustomEdit) == "function") {
            fnCustomEdit();

            return;
        }
        _fnEdit();
    },
    //删除
    fnDelete: function () {
        //debugger
        //_SelectItems,grid 在dojo.common.list.base.js 定义
        var item = grid.selection.getSelected();
        //var sItems = _SelectItems == undefined ? [] : _SelectItems;
        if (typeof (fnCustomDelete) == "function") {
            fnCustomDelete(item);
            return;
        }
        _fnDelete(item);
    },
    //移动
    fnMove: function () {
        if (typeof (fnCustomMove) == "function") {
            fnCustomMove();
            return;
        }
        _fnMove();
    },
    //查询
    fnQuery: function () {
        if (typeof (fnCustomQuery) == "function") {
            fnCustomQuery();
            return;
        }
        _fnQuery();
    },
    //快速查询
    fnQuickQuery: function (key) {
        if (typeof (fnCustomQuickQuery) == "function") {
            fnCustomQuickQuery(key);
            return;
        }
        _fnQuickQuery();
    },
    //全屏
    fnFullScreen: function () {
    },
    //退出
    fnCancel: function () {
        if (typeof (fnCustomCancel) == "function") {
            fnCustomCancel();
            return;
        }
        _fnCancel();
    },
    //打印
    fnPrint: function () {
        if (typeof (fnCustomPrint) == "function") {
            fnCustomPrint();
            return;
        }
        _fnPrint();
    }
    //下一
    , fnNext: function () {
        if (typeof (fnCustomNext) == "function") {
            fnCustomNext();
            return;
        }
        _fnNext();
    }
    //最后
    , fnLast: function () {
        if (typeof (fnCustomLast) == "function") {
            fnCustomLast();
            return;
        }
        _fnLast();
    }
    //第一
    , fnFirst: function () {
        if (typeof (fnCustomFirst) == "function") {
            fnCustomFirst();
            return;
        }
        _fnFirst();
    }
    //前一
    , fnPriv: function () {
        if (typeof (fnCustomPriv) == "function") {
            fnCustomPriv();
            return;
        }
        _fnPriv();
    }
    //保存
    , fnSave: function () {
        if (typeof (fnCustomSave) == "function") {
            fnCustomSave();
            return;
        }
        _fnSave();
    }
    //
    , fnSaveAndAddNew: function () {
        if (typeof fnCustomSaveAndAddNew === "function") {
            fnCustomSaveAddnAddNew();
            return;
        }
        _fnSaveAndAddNew();
    }
    //
    , fnSaveAndCancel: function () {
        if (typeof fnCustomSaveAndCancel === "function") {
            fnCustomSaneAndCancel();
            return;
        }
        _fnSaveAndCancel();
    }
    //应用
    , fnApply: function () {
        if (typeof (fnCustomApply) == "function") {
            fnCustomApply();
            return;
        }
        _fnApply();
    }
    //转换
    , fnTranslate: function () {
        if (typeof (fnCustomTranslate) == "function") {
            fnCustomTranslate();
            return;
        }
        _fnTranslate();
    }
    //确认
    , fnOK: function () {
        if (typeof (fnCustomOK) == "function") {
            fnCustomOK();
            return;
        }
        _fnOK();
    }
    //退回
    , fnReject: function () {
        if (typeof (fnCustomReject) == "function") {
            fnCustomReject();
            return;
        }
        _fnReject();
    }
    //拷贝
    , fnCopy: function () {
        if (typeof (fnCustomCopy) == "function") {
            fnCustomCopy();
            return;
        }
        _fnCopy();
        //parent.showD("Employee", 600, 450);
    }
    //退出
    , fnExit: function () {
        if (typeof (fnCustomExit) == "function") {
            fnCustomExit();
            //return;
        }
        _fnExit();
        //parent.showD("Employee", 900, 500);
    }
    //設置用戶
    , fnSetUser: function () {
        if (typeof (fnCustomSetUser) == "function") {
            fnCustomSetUser();
            return;
        }
        _fnSetUser();
        //parent.showD("hrEmployee", 1000, 500);
    }
    //
    , fnSetFuncOper: function () {//
        if (typeof fnCustomSetFuncOper === "function") {
            fnCustomSetFuncOper();
            return;
        }
        _fnSetFuncOper();
    }
    , fnSetFunc: function () {
        if (typeof fnCustomSetFunc === "function") {
            fnCustomSetFunc();
            return;
        }
        //getSelectItems(grid);
        _fnSetFuncOper();
    }
    //定义按钮
    , fnCommonBtnFn: function (btn, fn) {
        //alert(btn);
        //parent.showD("Employee", 600, 450);
        switch (btn) {
            case "fnAdd":
                this.fnAdd();
                break;
            case "fnEdit":
                this.fnEdit();
                break;
            case "fnSave":
                this.fnSave();
                break;
            case "fnSaveAndAdd":
                this.fnSaveAndAddNew();
                break;
            case "fnSaveAndCancel":
                this.fnSaveAndCancel();
                break;
            case "fnCopy":
                this.fnCopy();
                break;
            case "fnExit":
                this.fnExit();
                break;
            case "fnDelete":
                this.fnDelete();
                break;
            case "fnSetUser":
                if (!parent) {
                    //window.showModalDialog("http://www.china.com");
                    fnWindowOpen("http://www.china.com", "_blank");
                } else {
                    this.fnSetUser();
                }
                //alert("");
                break;
            case "fnSetFuncOper":
                this.fnSetUser();
                break;
            case "fnSetFunc":
                this.fnSetFunc();
                break;
            default:
                if (typeof (_fn) == "function") {
                    _fn();
                }
                //alert("");
                break;
        }
    }
}

var fnCommonBtnFn = function (btn) {
    
    iSunToolButton.fnCommonBtnFn(btn);
    //debugger
}



///打开新窗口
var fnWindowOpen = function (url, name, width, height) {
    window.open(url, "_blank", "alwaysRaised","height=600,width=800,status=yes,toolbar=yes,menubar=no,location=no,resizable=yes", false);
}

//-------------------------------------------
// fnRefreshData()
//-------------------------------------------
var fnRefreshData = function () {
}


///-----------------------
// 
// 删除当前所选数据
//------------------------
function _fnDelete(item) {
    alert(item.length);
}

///----------------------
///新增数据
///----------------------//
function _fnAdd() {
    //alert("add");
    parent.showD(const_EditEntity,850, 450, '人事管理', '');
}

///----------------------
///
///----------------------
function _fnEdit() {
    //alert("edit");
    if (_SelectItems.length > 0) {
        id = eval("_SelectItems[0]." + const_entityID);
       parent.showD(const_EditEntity, 850, 450, '人事管理', id);

    } 
    
}

///---------------------
///数据保存
///---------------------
function _fnSave() {
}
//-------------------------------------------
//查询执行
//-------------------------------------------
var fnQueryRe = function (condition) {
    if (typeof (fnCustomQueryRe) == "function") {
        fnCustomQueryRe();
        return;
    } else {
        const_CustomCondition = condition;
        fnRefreshData();
    }
}

///-------------------------------------------
///快速搜索
///-------------------------------------------
var fnQuciklyQuery = function () {
    if (const_QueryField == undefined || const_QueryField == "") {
        return;
    }
    var _keyword = document.getElementById("QueryContext").value;
    if (_keyword == "") {
        return;
    }
    var _chk = document.getElementById("checkAndOr").checked;
    //alert(_chk);
    var _opr = _chk ? " and " : " or ";
    //alert(_opr);
    var _fields = const_QueryField.split(",");
    var _keys = _keyword.split(" ");
    var _condition = "";
    for (n = 0; n < _keys.length; n++) {
        if (_keys[n] == "") {
            continue;
        }
        if (n == 0) {
            _condition = " ( "
        }
        else {
            _condition = _condition + _opr + " ( ";
        }
        for (i = 0; i < _fields.length; i++) {
            if (i == 0) {
                _condition = _condition + " (" + _fields[i] + " like '%" + _keys[n] + "%')  ";
            }
            else {
                _condition = _condition + " or (" + _fields[i] + " like '%" + _keys[n] + "%')  "
            }
        }
        _condition = _condition + " )";
    }
    //alert(_condition);
    fnQueryRe(encodeURI(_condition));
}